local skel = fk.CreateSkill {
  name = "lb_zero__yuanchi",
  tags = { Skill.Limited }
}

Fk:loadTranslationTable {
  ["lb_zero__yuanchi"] = "辕驰",
  [":lb_zero__yuanchi"] = "<b>限定技</b>，你可以将你场上的一张牌当【木牛流马】使用，你移动此牌时，可以改为对目标造成等同于扣置牌数的伤害，然后销毁之。",

  ["#lb_zero__yuanchi"] = "辕驰：你可以你场上的一张牌当【木牛流马】使用",
  ["#lb_zero__yuanchi-damage"] = "辕驰：你可以销毁 %arg ，对 %src 造成 %arg2 点伤害",

  ["$lb_zero__yuanchi1"] = "一边一个。",
  ["$lb_zero__yuanchi2"] = "用一份热，发一份光！",
  ["$lb_zero__yuanchi3"] = "哼，爆破工程，启动！",
  ["$lb_zero__yuanchi4"] = "这孩子真是可爱…到爆炸！",
}


skel:addEffect("viewas", {
  audio_index = { 1, 2 },
  anim_type = "big",
  pattern = "role__wooden_ox",
  prompt = "#lb_zero__yuanchi",
  expand_pile = function(self, player)
    return player:getCardIds("j")
  end,
  card_filter = function(self, player, to_select, selected, selected_targets)
    return #selected == 0 and table.contains(player:getCardIds("ej"), to_select)
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("role__wooden_ox")
    c.skillName = skel.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    player.room:setCardMark(Fk:getCardById(use.card.subcards[1]), skel.name, player.id)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
})

skel:addEffect(fk.BeforeCardsMove, {
  audio_index = { 3, 4 },
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and #player:getPile("$role_carriage") > 0 then
      for _, move in ipairs(data) do
        if move.from == player and move.to and move.to:isAlive() and move.toArea == Card.PlayerEquip and move.moveReason == fk.ReasonPut
            and move.skillName == "role__wooden_ox_skill&" and move.proposer == player then
          for _, info in ipairs(move.moveInfo) do
            if info.virtualEquip and info.virtualEquip.name == "role__wooden_ox" and Fk:getCardById(info.cardId):getMark(skel.name) == player.id then
              event:setCostData(self, { tos = { move.to }, cards = { info.cardId }, card = info.virtualEquip })
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cost_data = event:getCostData(self)
    return player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#lb_zero__yuanchi-damage:" ..
          cost_data.tos[1].id .. "::" .. cost_data.card:toLogString() .. ":" .. #player:getPile("$role_carriage")
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    local cards = cost_data.cards
    room:cancelMove(data, cards)
    room:damage {
      from = player,
      to = cost_data.tos[1],
      skillName = skel.name,
      damage = #player:getPile("$role_carriage"),
    }
    room:moveCardTo(cards, Card.Void, nil, fk.ReasonJustMove, skel.name)
    room:sendLog {
      type = "#DestructCards",
      card = {cost_data.card},
    }
  end,
})

return skel
